<extend name="Public/base" />

<block name="body">
    <link href="__STATIC__/datetimepicker/css/datetimepicker.css" rel="stylesheet" type="text/css">
    <php>if(C('COLOR_STYLE')=='blue_color') echo '<link href="__STATIC__/datetimepicker/css/datetimepicker_blue.css" rel="stylesheet" type="text/css">';</php>
    <link href="__STATIC__/datetimepicker/css/dropdown.css" rel="stylesheet" type="text/css">
    <script type="text/javascript" src="__STATIC__/datetimepicker/js/bootstrap-datetimepicker.min.js"></script>
    <script type="text/javascript" src="__STATIC__/datetimepicker/js/locales/bootstrap-datetimepicker.zh-CN.js" charset="UTF-8"></script>
    <!-- 标题栏 -->
    <div class="main-title">
        <h2>订单管理</h2>
    </div>
    <div class="cf">
        <div class="fl">
            <form name="searchForm" action="{:U('index')}" method="POST">
                <input type="text" name="order_no" class="text input-2x" value="{$order_no}" placeholder="订单号">
                <input type="text" name="phone" class="text input-2x" value="{$phone}" placeholder="手机号">
                <input type="text" name="pick_no" class="text input-2x" value="{$pick_no}" placeholder="提单号">
                <input type="text" name="company_name" class="text input-2x" value="{$company_name}" placeholder="下单企业名称">

                状态：
                <select name="status">
                    <option value="-1" selected>全部</option>
                    <option value ="0" <?php if(isset($status)&&$status==0){ echo 'selected';} ?>>待支付</option>
                    <option value ="10" <?php if(isset($status)&&$status==10){ echo 'selected';} ?>>派单中</option>
                    <option value ="20" <?php if(isset($status)&&$status==20){ echo 'selected';} ?>>待司机接单</option>
                    <option value ="30" <?php if(isset($status)&&$status==30){ echo 'selected';} ?>>运输中</option>
                    <option value ="40" <?php if(isset($status)&&$status==40){ echo 'selected';} ?>>已到港</option>
                    <option value ="50" <?php if(isset($status)&&$status==50){ echo 'selected';} ?>>已完成</option>
                    <option value ="60" <?php if(isset($status)&&$status==60){ echo 'selected';} ?>>已取消</option>

                </select>
                <input type="text" id="start_date" name="start_date" class="text input-2x" value="{$start_date}" placeholder="装箱时间" /> 
                <input type="text" id="end_date" name="end_date" class="text input-2x" value="{$end_date}" placeholder="截关时间" />&nbsp; &nbsp;
                <input type="hidden" name="is_export" value="0" id="export-data">
                <button class="btn" type="submit">筛 选</button><!--            <button class="btn ajax-post confirm" url="{:U('changeStatus?method=deleteUser')}" target-form="ids">删 除</button>-->
                <a class="btn" id="export-data-btn" href="javascript:;">导 出</a>
            </form>
        </div>

        <!-- 高级搜索 -->
        <div class="search-form fr cf">
        </div>
    </div>
    <!-- 数据列表 -->
    <div class="data-table table-striped">
        <table class="">
            <thead>
                <tr>
                    <th class="">订单号</th>
                    <th class="">下单企业</th>
                    <th class="">提单号</th>
                    <th class="">订单状态</th>
                    <th class="">箱型</th>
                    <th class="">装箱时间</th>
                    <th class="">截关时间</th>
                    <th class="">装箱点</th>
                    <th class="">货重</th>
                    <th class="">运费</th>
                    <th class="">下单时间</th>
                    <th class="">接单车队</th>
                    <th class="">操作</th>

                </tr>
            </thead>
            <tbody>
            <notempty name="_list">
                <volist name="_list" id="vo">
                <tr <?php if($vo['order_status']==10&&$vo['fleet_id']==0):?>style='color:#da3f3f;'<?php elseif($vo['order_status']==10&&$vo['driver_id']==0):?>style='color:#1324f3;'<?php endif;?> >
                        <td>{$vo.order_no} </td>
                        <?php if(IS_CHEDUI<=1):?>
                        <td>{$vo.company_name}</td>
                        <?php else:?>
                        <td>集运邦</td>
                        <?php endif;?>
                        <td>{$vo.pick_no}</td>
                        <td><?php if($vo['order_status']==10&&$vo['fleet_id']==0):?>待分派车队<?php elseif($vo['order_status']==10&&$vo['driver_id']==0):?>待分派司机<?php else:?>{$status_map[$vo['order_status']]}<?php endif;?></td>
                        <td><?php echo $box[$vo['order_type']]?></td>
                        <td>{$vo.shipment_time}</td>
                        <td>{$vo.cutoff_time}</td>
                        <td>{$vo.province}{$vo.city}{$vo.address}{$vo.address_desc}</td>
                        <td>{$vo.weight_desc}</td>
                        <td>{$vo.order_price}</td>
                        <td>{$vo.create_time}</td>
                        <td>{$vo.fleet_name}</td>
                        <td>
                            <a href="{:U('info',array('id'=>$vo['order_id']))}">订单详情</a>

                            <?php if($vo['order_status']==10&&$vo['fleet_id']==0):?>
                            <br/>
                            <a href="javascript:;" data-id="{$vo['order_id']}"  class="chedui">分派车队</a>
                            <?php elseif($vo['order_status']==10&&$vo['driver_id']==0):?>
                            <br/>
                            <a href="javascript:;" data-id="{$vo['order_id']}" chedui-id="{$vo['fleet_id']}"  class="siji">分派司机</a>
                            <?php endif;?>

                        </td>
                    </tr>
                </volist>
                <else/>
                <td colspan="20" class="text-center"> aOh! 暂时还没有内容! </td>
            </notempty>
            </tbody>
        </table>
    </div>
    <div class="page">
        {$_page}
    </div>
    <div class="show-box-back"  style="display: none;">
    </div>
    <!-- 分派车队 -->
    <div class="show-box" id="js-chedui" style="display: none;">
        <input type="hidden" name="order_id" id="js-chedui-id">
        <div class="show-box-msg" >
            派单给车队
        </div>
        <div class="show-box-msg-title">
            用户希望优先派单给:<span id="youxian"></span>
        </div>
        <div class="show-box-msg-area">
            <select name="chedui_id" id="chedui_id">
                <option value="0" selected>请选择接单车队</option>
                <notempty name="fleetlist">
                    <volist name="fleetlist" id="vo">
                        <option value="{$vo.fleet_id}" selected>{$vo.fleet_name}</option>
                    </volist>
                </notempty>

            </select>
        </div>
        <div class="show-box-bottom">
            <button class="js-show-btn-cancel btn btn-return" >返 回</button>
            <button class="btn submit-btn" id="submit-chedui" >派 单</button>

        </div>
    </div>

    <div class="show-box" id="js-siji" style="display: none;">
        <input type="hidden" name="order_id" id="js-siji-id">
        <div class="show-box-msg" >
            派单给司机
        </div>
        <div class="show-box-msg-title">
            用户希望优先派单给:<span id="youxian-siji"></span>
        </div>
        <div class="show-box-msg-area">
            <select name="siji_id" id="siji_id">
                <option value="0" selected>请选择接单司机</option>

            </select>
        </div>
        <div class="show-box-bottom">
            <button class="js-show-btn-cancel btn btn-return" >返 回</button>
            <button class="btn submit-btn" id="submit-siji" >派 单</button>

        </div>
    </div>
</block>

<block name="script">
    <script src="__STATIC__/thinkbox/jquery.thinkbox.js"></script>

    <script type="text/javascript">
        //搜索功能
        $("#export-data-btn").click(function () {
            $("#export-data").val(1);
            $('[name="searchForm"]').submit();
        });
        //回车搜索
        $(".search-input").keyup(function (e) {
            if (e.keyCode === 13) {
                $("#search").click();
                return false;
            }
        });
        $('#start_date').datetimepicker({
            format: 'yyyy-mm-dd',
            language: "zh-CN",
            minView: 2,
            autoclose: true
        });
        $('#end_date').datetimepicker({
            format: 'yyyy-mm-dd',
            language: "zh-CN",
            minView: 2,
            autoclose: true
        });

        $("#search").click(function () {
            var url = $(this).attr('url');
            var query = $('.search-form').find('input').serialize();
            query = query.replace(/(&|^)(\w*?\d*?\-*?_*?)*?=?((?=&)|(?=$))/g, '');
            query = query.replace(/^&/g, '');
            if (url.indexOf('?') > 0) {
                url += '&' + query;
            } else {
                url += '?' + query;
            }
            window.location.href = url;
        });

        //搜索功能
        $(".chedui").click(function () {
            var id = $(this).attr("data-id");
            $.post("{:U('getRecmdDriver')}", {id: id}, function (res) {
                $("#youxian").html(res.data);
            });
            $('#js-chedui').show();
            $('.show-box-back').show();
            $('#js-chedui-id').val(id);
        });
        //搜索功能
        $(".siji").click(function () {
            var id = $(this).attr("data-id");
            var cheduiid = $(this).attr("chedui-id");
            $.post("{:U('getRecmdDriver')}", {id: id, chedui_id: cheduiid}, function (res) {
                $("#youxian-siji").html(res.data);
                $.each(res.driver, function (index, value) {
                    $("#siji_id").append("<option value='" + value.driver_id + "'>" + value.driver_name + "</option>");
                });
            });
            $('#js-siji').show();
            $('.show-box-back').show();
            $('#js-siji-id').val(id);
        });

        $("#submit-chedui").click(function () {
            var id = $("#js-chedui-id").val();
            var chedui_id = $("#chedui_id option:selected").val();
            $.post("{:U('allotFleet')}", {id: id, chedui_id: chedui_id}, function (res) {
                if (res.status) {
                    updateAlert('分派车队成功', 'alert-success');
                    setTimeout(function () {
                        location.reload();
                    }, 1500);
                }
            });
        });
        $("#submit-siji").click(function () {
            var id = $("#js-siji-id").val();
            var siji_id = $("#siji_id option:selected").val();
            $.post("{:U('allotDriver')}", {id: id, siji_id: siji_id}, function (res) {
                if (res.status) {
                    updateAlert('分派司机成功', 'alert-success');
                    setTimeout(function () {
                        location.reload();
                    }, 1500);
                }
            });
        });

        //导航高亮
        highlight_subnav("{:U('Order/index')}");
    </script>
</block>
